package com.onlineClass.edu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.onlineClass.edu.base.BaseApiController;
import com.onlineClass.edu.base.BaseResponse;
import com.onlineClass.edu.cache.LocalCache;
import com.onlineClass.edu.constant.LocalCacheKeyConstants;
import com.onlineClass.edu.entity.EduCourseClass;
import com.onlineClass.edu.entity.dto.response.EduCourseClassRespDto;
import com.onlineClass.edu.entity.dto.response.EduCourseRespDto;
import com.onlineClass.edu.entity.requestDto.EduCourseReqDto;
import com.onlineClass.edu.service.IEduCourseClassService;
import com.onlineClass.edu.service.impl.EduCourseClassServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author denghui
 * @since 2024-04-19
 */
@RestController
@RequestMapping("/course")
@Slf4j
public class EduCourseClassController extends BaseApiController {
    @Autowired
//    IEduCourseClassService iEduCourseClassService;
    EduCourseClassServiceImpl eduCourseClassService;
    @GetMapping("/getAllClass")
    public BaseResponse getAll() {
        //从db里查询数据，比较耗时
//        return setResultSuccessData(eduCourseClassService.getAll());
        //直接从JVM缓存中查找数据。。。只需要10~20ms
        List<EduCourseClassRespDto> allEduCourseClassRespDtos = new ArrayList<>();
        allEduCourseClassRespDtos = LocalCache.get(LocalCacheKeyConstants.COURSE_ALLCOURSECLASSLIST,allEduCourseClassRespDtos);
        if(CollectionUtils.isEmpty(allEduCourseClassRespDtos)){
            log.error("[从集合中为查找到所有的课程分类数据]");
            return setResultError("未查找到数据");
        }
        return  setResultSuccessData(allEduCourseClassRespDtos);
    }

}
